<template>
 <!-- 技术-专家委员会-技术服务需求 -->
    <base-breadcrumb>
        <searchData :search-data="searchArr" @search="search"/>
        <a-card>
          <list-table
            ref="table"
            class="export-table"
            :columns="columns"
            :startIndex="0"
            :request="loadData"
            :statisticsConfig="{use: true, temp: statisticsTemp}"
            :export-config="{ use: true, select: '技术服务需求', all: '技术服务需求',customColumns: customColumns}"
            :export-permission="{select: 'tm_013_exp_06',all: 'tm_013_exp_06'}">  
            <template slot="prefix">
              <a-button type="primary" @click="handleManage(2)"  v-btnPermission="'tm_013_add_01'">新增</a-button>
            </template>            
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            <template slot="status" slot-scope="text, record">
                <list-status  conversion="en" :is-approval="true" :status="getStatus(record.auditStatus)"/>
            </template>
            <!-- 操作 -->
              <template slot="action" slot-scope="text, record">
                  <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'tm_013_loo_04'">查看</a>
                    <template v-btnPermission="'tm_013_edi_02'"   v-if="(record.auditStatus*1!==1 && record.auditStatus*1 !== 3 && record.auditStatus*1!== 4) &&hideBuquBtn()" >
                        <a @click="handleManage(1, record)">编辑</a>
                        </template>
                      <template v-if="record.auditStatus*1 === 5">
                          <!-- 删除 -->
                            <template v-btnPermission="'tm_013_del_03'" v-if="(record.auditStatus*1 ===0 || record.auditStatus*1 ===5) && hideBuquBtn()">
                                <a @click="handleRemoveParams(record)" >删除</a>
                            </template>

                            <template v-btnPermission="'tm_013_loo_04'"  v-if="
                                record.auditStatus*1  === 3 ||
                                record.auditStatus*1 === 1 ||
                                record.auditStatus*1 === 5||
                                record.auditStatus*1  === 4
                                ">
                                <approval-button :id="record.id" :status="getStatus(record.auditStatus)" />
                            </template>
                      </template>
                      <template v-else>
                        <!-- 删除 -->
                        <template v-btnPermission="'tm_013_del_03'"   v-if="(record.auditStatus*1 ===0 || record.auditStatus*1 ===5) && hideBuquBtn()">
                            <a @click="handleRemoveParams(record)">删除</a>
                        </template>

                        <template v-btnPermission="'tm_013_loo_04'"  v-if="
                            record.auditStatus*1  === 3 ||
                            record.auditStatus*1 === 1 ||
                            record.auditStatus*1 === 5||
                            record.auditStatus*1  === 4
                            ">
                            <approval-button :id="record.id" :status="getStatus(record.auditStatus)" />
                        </template>
                      </template>
                  </MoreButton>
                </template>
          </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { getPageTechnicalServiceNeeds,getTopTotal,delTechnicalServiceNeeds} from '@/api/technical/serviceDemand'
import {technicalServiceType,handleStatusType,typeListApproval} from './model'
import { getAllBranchCompany } from '@/api/commons'
const columns = [
    { title: '所属组织机构',width: '200px',dataIndex: 'branchComName',ellipsis: true},
    {title: '所属项目',width: '200px',dataIndex: 'projectName',ellipsis: true},
    {title: '技术服务名称',width: '200px',dataIndex: 'name',ellipsis: true},
    {title: '技术服务类型',width: '120px',dataIndex: 'typeName',ellipsis: true},
    {title: '时间',width: '240px',ellipsis: true,dataIndex:'startAndEndTime'},
    {title: '联系人',width: '200px',dataIndex: 'linkmanPost',ellipsis: true},
    {title: '联系人手机',width: '120px',dataIndex: 'phone',ellipsis: true},
    {title: '处理状态',width: '120px',dataIndex: 'handleStatusName',ellipsis: true},
    {title: '状态',width: '120px',dataIndex: 'auditStatus',scopedSlots: { customRender: 'status' },ellipsis: true},
    {title: '操作',dataIndex: 'action',fixed: 'right',width: '180px',scopedSlots: { customRender: 'action' },},
]
export default {
    name:'a'+Date.now(),
    components: {
        SelectSubCompany,
        SelectProject,
    },
    data() {
        this.columns = columns
        this.customColumns = columns.slice(0,7)
        return {
            loadData: (parameter) => {
              let that = this
              parameter.pageNum = parameter.pageNo;
              delete parameter.pageNo;
              const requestParameters = Object.assign({}, parameter, { param: that.queryParam })
              getTopTotal(requestParameters)
              .then((res) => {
                  this.loading.isTable = false
                  this.SummaryData = res.data
              })
              .catch(() => {
                  this.loading.isTable = false
              })
              return getPageTechnicalServiceNeeds(requestParameters).then((res) => {
                return res
              })
            },
            loading: {
                isTable: false,
                subChangeCycle: false
            },
            queryParam: {},
            companyList:[],
            SummaryData:{
              demand:0,   // 发起需求(不包括未提交的数据)
              pass:0,   //	审批通过
              submitted:0,  //审批中
              hasHandle:0, //已处理
              handle:0,     //处理中
              noHandle:0,  //未处理
            },    //汇总
        }
    },
    computed:{
      searchArr() {
        return [
         // 搜索框
         {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
      //  {name: '所属组织机构',value: 'branchComId',placeholder: '请选择',type: 'select', data: this.companyList},
      //  {name: '所属项目',placeholder: '请选择',valueKey: 'projectId',keyValue: 'branchComId',type: SelectProject,isSelf:false,},
       {name: '技术服务名称',value: 'name',type: 'input',},
       {name: '技术服务类型',value: 'type',type: 'select',data: technicalServiceType},
       {name: '时间',type: 'dateRange',value: 'submitTime',
        attr: {
            rangeFormat: ['startTime', 'endTime']
        }
    },
      {name: '联系人',value: 'linkmanPost',type: 'input',},
      {name: '处理状态',value: 'handleStatus',type: 'select',data: handleStatusType},
      {name: '状态',value: 'auditStatus',type: 'select',data: typeListApproval,}
        ]
      }
    },
     created() {
      this.querCompany()
    },
    methods: {
      querCompany() {
          return getAllBranchCompany({tagCodes: ['BC']}).then((res) => {
            let co = [{
              id: "53085e2c9f1f4685801ef31994f57c49",
              name: "总部机关",
            }]
           res.data = [ ...co, ...res.data ];
        let datas = res.data.map((item, index) => {
          return { label: item.name, value: item.id }
        })
        this.companyList = datas
        })
        },
       // 删除数据
      handleRemoveParams(e) {
            let that = this
            that.$confirm({
                title: '温馨提示',
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return delTechnicalServiceNeeds({ id: e.id })
                        .then((res) => {
                            that.$message.success('删除成功！')
                            that.$refs.table.refresh()
                        })
                        .catch((res) => {
                            that.$message.warning('删除失败！')
                        })
                },
            })
        },
          getStatus(str){
            let  strText = '';
             switch (str) {
                case 0:
                    strText = "DRAFT";
                    break;
                case 1:
                    strText = "SUBMITTED";
                    break;
                case 2:
                    strText = "UPLOAD";
                    break;
                case 3:
                    strText = "PAST";
                    break;
                case 4:
                    strText = "ABOLISH";
                    break;
                case 5:
                    strText = "REJECTED";
                    break;
                default:
                    strText = "";
            }
            return strText;
        },
        search(values) {
          this.queryParam = { ...values }
          this.$refs.table.refresh()
        },
        detailed(record, type) {
            this.$router.push({
                path: '/technical/ShiGroup/newPlan',
                query: {
                    type,
                    id: record.id,
                },
            })
        },
        /**
         * 统计
         */
        statisticsTemp() {
          return (
            <span>
              <span>发起需求：<a>{this.SummaryData.demand}</a></span>
              <span style="margin-left:10px">审批通过：<a>{ this.SummaryData.pass } </a></span>
              <span style="margin-left:10px">审批中：<a>{ this.SummaryData.submitted }</a></span>
              <span style="margin-left:10px">已处理：<a>{ this.SummaryData.hasHandle }</a></span>
              <span style="margin-left:10px">处理中：<a>{ this.SummaryData.handle }</a></span>
              <span style="margin-left:10px">未处理：<a>{ this.SummaryData.noHandle }</a></span>
            </span>
          )
        },
         // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateServiceDemand',
                query
            })
        }
    },
    mounted(){
      // this.$set(this.searchArr,0,{name: '所属组织机构',type: 'select', value: 'branchComId', data:this.ownOrgList});
    }
}
</script>

<style lang="less">
</style>
